package com.zzy.jtxdemo;

import jodd.jtx.JtxTransaction;
import jodd.jtx.JtxTransactionManager;
import jodd.jtx.JtxTransactionMode;

public class TestDemo {

	public static void main(String[] args) {
		// [1] create jtx manager and register our resource manager
		JtxTransactionManager jtxManager = new JtxTransactionManager();
		jtxManager.registerResourceManager(new WorkResourceManager());

		// [2] request jtx
		JtxTransaction jtx = jtxManager.requestTransaction(
				new JtxTransactionMode().propagationRequired().readOnly(false)
				);

		// [3] requrest resource i.e. start jtx
		WorkSession work = jtx.requestResource(WorkSession.class);

		// [4] work
		work.writeValue("new value");

		// [5] done
		jtx.commit();

		// [6] cleanup
		jtxManager.close();

	}

}
